% !Mode:: "TeX:UTF-8"
%  Authors: 张井   Jing Zhang: prayever@gmail.com     天津大学2010级管理与经济学部信息管理与信息系统专业硕士生
%           余蓝涛 Lantao Yu: lantaoyu1991@gmail.com  天津大学2008级精密仪器与光电子工程学院测控技术与仪器专业本科生
%此模版以天津大学本科毕业论文模板为基础，保留了原有的文件名和内容注释，由海南大学张永辉进行了修改，2023.5.27，宁波警官学院姬晓鹏博士（海南大学电子信息工程2009级本科）帮助修改了目录格式
%%%%%%%%%%%%%%% Fonts Definition and Basics 字体定义%%%%%%%%%%%%%%%
%\newcommand{\song}{\CJKfamily{song}}    % 宋体
%\newcommand{\fs}{\CJKfamily{fs}}        % 仿宋体
%\newcommand{\kai}{\CJKfamily{kai}}      % 楷体
%\newcommand{\hei}{\CJKfamily{hei}}      % 黑体
%\newcommand{\li}{\CJKfamily{li}}        % 隶书
\newcommand{\song}{\songti}    % 宋体
\newcommand{\fs}{\fangsong}        % 仿宋体
\newcommand{\kai}{\kaishu}      % 楷体
\newcommand{\hei}{\heiti}      % 黑体
\newcommand{\li}{\lishu}        % 隶书
\newcommand{\xiaochu}{\fontsize{52pt}{30pt}\selectfont}       % 小初, 单倍行距
\newcommand{\yihao}{\fontsize{26pt}{26pt}\selectfont}       % 一号, 单倍行距
\newcommand{\xiaoyi}{\fontsize{24pt}{24pt}\selectfont}      % 小一, 单倍行距
\newcommand{\erhao}{\fontsize{22pt}{1.25\baselineskip}\selectfont}       % 二号, 1.25倍行距
\newcommand{\xiaoer}{\fontsize{18pt}{18pt}\selectfont}      % 小二, 单倍行距
\newcommand{\sanhao}{\fontsize{16pt}{16pt}\selectfont}      % 三号, 单倍行距
\newcommand{\xiaosan}{\fontsize{15pt}{15pt}\selectfont}     % 小三, 单倍行距
\newcommand{\sihao}{\fontsize{14pt}{14pt}\selectfont}       % 四号, 单倍行距
\newcommand{\xiaosi}{\fontsize{12pt}{12pt}\selectfont}      % 小四, 单倍行距
\newcommand{\wuhao}{\fontsize{10.5pt}{10.5pt}\selectfont}   % 五号, 单倍行距
\newcommand{\xiaowu}{\fontsize{9pt}{9pt}\selectfont}        % 小五, 单倍行距

%\CJKtilde  % 重新定义了波浪符~的意义
% JUST DON'T USE CJK
% 使用 ctexbook 之后已无必要

%% 修复目录格式显示问题，注释下列行
  \newcommand\prechaptername{第}
  \newcommand\postchaptername{章}
  \newcommand\presectionname{第}
  \newcommand\postsectionname{节}
  \newcommand\postsubsectionname{.}
%% pre及postname改为空
 %\newcommand\prechaptername{}
 %\newcommand\postchaptername{}
% \newcommand\presectionname{}
 %\newcommand\postsectionname{}

\punctstyle{hangmobanjiao}             % 调整中文字符的表示，行内占一个字符宽度，行尾占半个字符宽度

% 调整罗列环境的布局
\setitemize{leftmargin=3em,itemsep=0em,partopsep=0em,parsep=0em,topsep=-0em}
\setenumerate{leftmargin=3em,itemsep=0em,partopsep=0em,parsep=0em,topsep=0em}

% 避免宏包 hyperref 和 arydshln 不兼容带来的目录链接失效的问题。
\def\temp{\relax}
\let\temp\addcontentsline
\gdef\addcontentsline{\phantomsection\temp}

% 自定义项目列表标签及格式 \begin{publist} 列表项 \end{publist}
\newcounter{pubctr} %自定义新计数器
\newenvironment{publist}{%%%%%定义新环境
\begin{list}{[\arabic{pubctr}]} %%标签格式
    {
     \usecounter{pubctr}
     \setlength{\leftmargin}{2.5em}   % 左边界 \leftmargin =\itemindent + \labelwidth + \labelsep
     \setlength{\itemindent}{0em}     % 标号缩进量
     \setlength{\labelsep}{0.5em}       % 标号和列表项之间的距离,默认0.5em
     \setlength{\rightmargin}{0em}    % 右边界
     \setlength{\topsep}{0ex}         % 列表到上下文的垂直距离
     \setlength{\parsep}{0ex}         % 段落间距
     \setlength{\itemsep}{0ex}        % 标签间距
     \setlength{\listparindent}{0pt}  % 段落缩进量
    }}
{\end{list}}

\makeatletter
\renewcommand\normalsize{
  \@setfontsize\normalsize{12pt}{12pt} % 小四对应 12 pt
  \setlength\abovedisplayskip{4pt}
  \setlength\abovedisplayshortskip{4pt}
  \setlength\belowdisplayskip{\abovedisplayskip}
  \setlength\belowdisplayshortskip{\abovedisplayshortskip}
  \let\@listi\@listI}
\def\defaultfont{\renewcommand{\baselinestretch}{1.63}\normalsize\selectfont} % 设置行距

\renewcommand{\CJKglue}{\hskip -0.1 pt plus 0.08\baselineskip} % 控制字间距，使每行 34 个汉字
\makeatother

%%%%%%%%%%%%% Contents 目录%%%%%%%%%%%%%%%%%
\renewcommand{\contentsname}{\sanhao 目\qquad 录}
\setcounter{tocdepth}{2} % 控制目录深度
% 使用 ctexbook 之后已无必要
%\titlecontents{chapter}[2em]{\vspace{.5\baselineskip}\xiaosan\song}
             %{\prechaptername\CJKnumber{\thecontentslabel}\postchaptername\qquad}{}
             %{\hspace{.5em}\titlerule*[10pt]{$\cdot$}\sihao\contentspage}
%下面是定义目录的格式
%章（一级）
\titlecontents{chapter}[1em]{\vspace{.5\baselineskip}\sihao\song}
             {\thecontentslabel}{}
             {\hspace{.5em}\titlerule*[3pt]{$\cdot$}\sihao\contentspage}         %页码字号
%节（二级）
\titlecontents{section}[2em]{\vspace{.25\baselineskip}\sihao\song}
             {\thecontentslabel\quad}{}
             {\hspace{.5em}\titlerule*[3pt]{$\cdot$}\sihao\contentspage}         %页码字号
%小节（三级）
\titlecontents{subsection}[3em]{\vspace{.25\baselineskip}\sihao\song}
             {\thecontentslabel\quad}{}
             {\hspace{.5em}\titlerule*[3pt]{$\cdot$}\sihao\contentspage}        %页码字号

%% 修复目录显示格式问题

%% 使用ctexset重新定义标题编号格式
\ctexset{
chapter={name={,}, number=\arabic{chapter}},
section={number=\arabic{chapter}.\arabic{section}},
subsection={number=\arabic{chapter}.\arabic{section}.\arabic{subsection}},
}

%%%%%%%%%% Chapter and Section 章节格式 %%%%%%%%%%%%%
\setcounter{secnumdepth}{4}
\setlength{\parindent}{2em}

\renewcommand\thesection{\arabic{section}}
\renewcommand\thesubsection{\arabic{subsection}}

\renewcommand{\chaptername}{{\thechapter}}

\newcommand{\sectionname}{{\thechapter}.{\thesection}}
\newcommand{\subsectionname}{{\thechapter}.{\thesection}.{\thesubsection} }

%\centering设置摘要和ABSTRACT的Chapter标题居中，但不知道为什么改不了标题字体
\titleformat{\chapter}{\centering\bf\sanhao\song}{\song\chaptername}{1em}{}
\titlespacing{\chapter}{0pt}{0.1\baselineskip}{0.8\baselineskip}
\titleformat{\section}{\bf\sihao\song}{\song\sectionname}{1em}{}
\titlespacing{\section}{0pt}{0.1\baselineskip}{0.8\baselineskip}
%\titleformat{\section}{\sihao\hei}{\thesection}{1em}{}
%\titlespacing{\section}{0pt}{0.15\baselineskip}{0.25\baselineskip}
\titleformat{\subsection}{\bf\xiaosi\song}{\subsectionname}{0em}{}
\titlespacing{\subsection}{0pt}{0.1\baselineskip}{0.3\baselineskip}
\titleformat{\subsubsection}{\xiaosi\song}{\thesubsubsection}{1em}{}
\titlespacing{\subsubsection}{0pt}{0.05\baselineskip}{0.1\baselineskip}

%%%%%%%%%% Table, Figure and Equation 表格，插图，公式%%%%%%%%%%%%%
\renewcommand{\tablename}{表}                                     % 插表题头
\renewcommand{\figurename}{图}                                    % 插图题头
\renewcommand{\thefigure}{\arabic{chapter}-\arabic{figure}}       % 使图编号为 7-1 的格式 %\protect{~}
\renewcommand{\thesubfigure}{\alph{subfigure})}                   % 使子图编号为 a) 的格式
\renewcommand{\thesubtable}{(\alph{subtable})}                    % 使子表编号为 (a) 的格式
\renewcommand{\thetable}{\arabic{chapter}-\arabic{table}}         % 使表编号为 7-1 的格式
\renewcommand{\theequation}{\arabic{chapter}-\arabic{equation}}   % 使公式编号为 7-1 的格式
\newcommand{\ud}{\mathrm{d}}

%%%%%% 定制浮动图形和表格标题样式 %%%%%%
\makeatletter
\long\def\@makecaption#1#2{
   \vskip\abovecaptionskip
   \sbox\@tempboxa{\centering\wuhao\song{#1\quad #2} }
   \ifdim \wd\@tempboxa >\hsize
     \centering\wuhao\song{#1\quad #2} \par
   \else
     \global \@minipagefalse
     \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}
   \fi
   \vskip\belowcaptionskip}
\makeatother
\captiondelim{~~~~} %用来控制longtable表头分隔符

%%%%%%%%%% Theorem Environment 定理环境设置%%%%%%%%%%%%%%%%%
\theoremstyle{plain}
\theorembodyfont{\song\rmfamily}
\theoremheaderfont{\hei\rmfamily}
\newtheorem{theorem}{定理~}[chapter]
\newtheorem{lemma}{引理~}[chapter]
\newtheorem{axiom}{公理~}[chapter]
\newtheorem{proposition}{命题~}[chapter]
\newtheorem{prop}{性质~}[chapter]
\newtheorem{corollary}{推论~}[chapter]
\newtheorem{definition}{定义~}[chapter]
\newtheorem{conjecture}{猜想~}[chapter]
\newtheorem{example}{例~}[chapter]
\newtheorem{remark}{注~}[chapter]
%\newtheorem{algorithm}{算法~}[chapter]
\newenvironment{proof}{\noindent{\hei 证明：}}{\hfill $ \square $ \vskip 4mm}
\theoremsymbol{$\square$}

%%%%% Page: number, header and footer  页面：页码、页眉页脚%%%%%%%%%%

%\frontmatter 或 \pagenumbering{roman}
%\mainmatter 或 \pagenumbering{arabic}
\makeatletter
\renewcommand\frontmatter{\clearpage
  \@mainmatterfalse
  }
\makeatother

%%%%%%%%%%% Code: Listings from MCM Template 代码 %%%%%%%%%%%%

\definecolor{grey}{rgb}{0.8,0.8,0.8}
\definecolor{darkgreen}{rgb}{0,0.3,0}
\definecolor{darkblue}{rgb}{0,0,0.3}
\def\lstbasicfont{\fontfamily{pcr}\selectfont\footnotesize}
\lstset{%
% indexing
   % numbers=left,
   % numberstyle=\small,%
% character display
    showstringspaces=false,
    showspaces=false,%
    tabsize=4,%
% style
    frame=lines,%
    basicstyle={\footnotesize\lstbasicfont},%
    keywordstyle=\color{darkblue}\bfseries,%
    identifierstyle=,%
    commentstyle=\color{darkgreen},%\itshape,%
    stringstyle=\color{black}%
}
\lstloadlanguages{C,C++,Java,Matlab,Mathematica,Python}

%%%%%%%%%%%% References 参考文献 %%%%%%%%%%%%%%%%%
\renewcommand{\bibname}{参考文献}
% 重定义参考文献样式，来自thu
\makeatletter
\renewenvironment{thebibliography}[1]{
    \titleformat{\chapter}{\raggedright\sanhao\bf\song}{\chaptername}{2em}{}
   \chapter*{\bibname}
   \wuhao
   \list{\@biblabel{\@arabic\c@enumiv}}
        {\renewcommand{\makelabel}[1]{##1\hfill}
         \settowidth\labelwidth{0 cm}
         \setlength{\labelsep}{0pt}
         \setlength{\itemindent}{0pt}
         \setlength{\leftmargin}{\labelwidth+\labelsep}
         \addtolength{\itemsep}{-0.7em}
         \usecounter{enumiv}
         \let\p@enumiv\@empty
         \renewcommand\theenumiv{\@arabic\c@enumiv}}
    \sloppy\frenchspacing
    \clubpenalty4000
    \@clubpenalty \clubpenalty
    \widowpenalty4000
    \interlinepenalty4000
    \sfcode`\.\@m}
   {\def\@noitemerr
     {\@latex@warning{Empty `thebibliography' environment}}
    \endlist\frenchspacing}
\makeatother

\addtolength{\bibsep}{-0.5em}     % 缩小参考文献间的垂直间距
\setlength{\bibhang}{2em}         % 每个条目自第二行起缩进的距离

% 参考文献引用作为上标出现
%\newcommand{\citeup}[1]{\textsuperscript{\cite{#1}}}
\makeatletter
    \def\@cite#1#2{\textsuperscript{[{#1\if@tempswa , #2\fi}]}}
\makeatother
%% 引用格式
\bibpunct{[}{]}{,}{s}{}{,}

%%%%%%%%%%%% Cover 封面 %%%%%%%%%%%%%%%%%
% 封面、摘要、版权、致谢格式定义
\makeatletter
\def\ctitle#1{\def\@ctitle{#1}}\def\@ctitle{}
\def\cdegree#1{\def\@cdegree{#1}}\def\@cdegree{}
\def\caffil#1{\def\@caffil{#1}}\def\@caffil{}
\def\csubject#1{\def\@csubject{#1}}\def\@csubject{}
\def\cgrade#1{\def\@cgrade{#1}}\def\@cgrade{}
\def\cauthor#1{\def\@cauthor{#1}}\def\@cauthor{}
\def\cnumber#1{\def\@cnumber{#1}}\def\@cnumber{}
\def\csupervisor#1{\def\@csupervisor{#1}}\def\@csupervisor{}
\def\crank#1{\def\@crank{#1}}\def\@crank{}
\def\cdate#1{\def\@cdate{#1}}\def\@cdate{}
\long\def\cabstract#1{\long\def\@cabstract{#1}}\long\def\@cabstract{}
\long\def\eabstract#1{\long\def\@eabstract{#1}}\long\def\@eabstract{}
\def\ckeywords#1{\def\@ckeywords{#1}}\def\@ckeywords{}
\def\ekeywords#1{\def\@ekeywords{#1}}\def\@ekeywords{}
\def\cheading#1{\def\@cheading{#1}}\def\@cheading{}
\def\cdepartment#1{\def\@cdepartment{#1}}\def\@cdepartment{}

% 定义正文页眉页脚 
\pagestyle{fancy}
  \fancyhf{}
   \fancyhead[CO]{\song\wuhao \@cheading}  % 奇数页页眉显示海南大学本科毕业论文（设计）
  \fancyhead[CE]{\song\wuhao \@ctitle}  % 偶数页页眉显示论文题目
  %与开章页页眉设置要一致
    \fancyfoot[C]{\song\xiaowu ~\thepage~}
\newlength{\@title@width}

% 定义封面
\def\makecover{
%\cleardoublepage%
   \phantomsection
    \pdfbookmark[-1]{\@ctitle}{ctitle}

    \begin{titlepage}
      \vspace*{10.5pt}
      \begin{center}

  \begin{figure}[h]
  \centering
  \includegraphics[width=0.5\textwidth]{Thesis/figures/hnunamelogo.png}
  \end{figure}
  \vspace*{15pt}
  \hei\yihao{本~科~毕~业~论~文（设~计）}
  %\hei\erhao{（XXXX届·本科）}
  \vspace*{10.5pt}

  %\begin{figure}[h]
  %\centering
  %\includegraphics[width=0.3\textwidth]{Thesis/figures/hnulogo.png}
  %\end{figure}

  \vspace*{5pt}
  %\hei\sanhao{\textbf{题目：\@ctitle}}
  \vspace*{16pt}
  
  \vspace*{24pt}
  \renewcommand\arraystretch{1.5}
  \setlength{\@title@width}{10cm}
  {\xiaosan\song{\bf{
  \begin{tabular}{lc}
    题~~~~~~目：&  \underline{\makebox[\@title@width][c]{\@ctitle}} \\
    %如果题目过长，可以在题目的文字中间加入“\kern -1pt”
    学~~~~~~号：&  \underline{\makebox[\@title@width][c]{\@cnumber}} \\
    姓~~~~~~名：&  \underline{\makebox[\@title@width][c]{\@cauthor}} \\
    年~~~~~~级：&  \underline{\makebox[\@title@width][c]{\@cgrade}} \\
    学~~~~~~院：&  \underline{\makebox[\@title@width][c]{\@caffil}} \\
    系~~~~~~别：&  \underline{\makebox[\@title@width][c]{\@cdepartment}} \\
    专~~~~~~业：&  \underline{\makebox[\@title@width][c]{\@csubject}} \\
    指导教师： &  \underline{\makebox[\@title@width][c]{\@csupervisor~~\@crank}} \\
  \end{tabular}}}
 }
  \vspace*{21pt}

\song\sanhao{\textbf{\@cdate}}
\end{center}
\end{titlepage}

%%%%%%%%%%%%%%%%%%%    摘要和关键字 %%%%%%%%%%%%
\clearpage
\pagenumbering{Roman}                %摘要页码用大写罗马数字
\markboth{摘~~要}{摘~~要}
\pdfbookmark[0]{摘~~要}{cabstract}
\addcontentsline{toc}{chapter}{摘~~要}
%\chapter*{\centering\sanhao\hei\bfseries 摘\qquad 要}
\chapter*{\centering\sanhao\bf\song 摘\qquad 要}
\vspace{\baselineskip}
\song\defaultfont
\@cabstract
\vspace{\baselineskip}

\hangafter=1\hangindent=52.3pt\noindent
{\hei\xiaosi 关键词：} \@ckeywords
\thispagestyle{plain}

%%%%%%%%%%%%%%%%%%%   Abstract and Keywords   %%%%%%%%%%%%%%%%%%%
\clearpage
%\phantomsection
\markboth{Abstract}{Abstract}
\pdfbookmark[0]{Abstract}{eabstract}
\addcontentsline{toc}{chapter}{Abstract}
\chapter*{\centering\sanhao{\bf{Abstract}}}

\vspace{\baselineskip}
\@eabstract
\vspace{\baselineskip}

\hangafter=1\hangindent=60pt\noindent
{\textbf{Keywords:}\noindent} \@ekeywords
\thispagestyle{plain}
}
\makeatother
